<template>
  <el-form ref="formRef" :model="modelData" :rules="rules" label-width="100px">
    <el-form-item label="单据号" prop="billNo">
      <el-input v-model="modelData.billNo" placeholder="保存时自动生成" />
    </el-form-item>
    <el-form-item label="房产id" prop="detail[1].houseId" v-show="false">
      <el-input v-model="modelData.detail[1].houseId" placeholder="请输入房产id" />
    </el-form-item>
    <el-form-item label="房产名称" prop="detail[1].houseName">
      <el-input readonly v-model="modelData.detail[1].houseName" placeholder="请输入房产id" />
    </el-form-item>
    <el-form-item label="客户id" prop="detail[1].customerId">
      <el-input v-model="modelData.detail[1].customerId" placeholder="请输入客户id" />
    </el-form-item>
    <!-- <el-form-item label="设备id" prop="detail[1].equipId">
      <el-input v-model="modelData.detail[1].equipId" placeholder="请输入设备id" />
    </el-form-item> -->
    <el-form-item label="设备名称" prop="detail[1].equipId">
      <el-select filterable v-model="modelData.detail[1].equipId" placeholder="请选择设备"
        ><el-option v-for="item in equipList" :key="item.id" :label="item.name" :value="item.id" />
      </el-select>
    </el-form-item>
    <el-form-item label="生效时间" prop="detail[1].effTime">
      <el-date-picker
        v-model="modelData.detail[1].effTime"
        type="date"
        value-format="x"
        placeholder="选择生效时间"
        class="!w-1/1"
      />
    </el-form-item>
    <el-form-item
      :label="props.busScope == '0' ? '行码' : props.busScope == '1' ? '表码' : '蒸汽量读数'"
      prop="detail[1].bv01"
    >
      <el-input v-model="modelData.detail[1].bv01" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="尖" prop="detail[1].bv02">
      <el-input v-model="modelData.detail[1].bv02" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="峰" prop="detail[1].bv03">
      <el-input v-model="modelData.detail[1].bv03" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="平" prop="detail[1].bv04">
      <el-input v-model="modelData.detail[1].bv04" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item v-if="busScope == '1'" label="谷" prop="detail[1].bv05">
      <el-input v-model="modelData.detail[1].bv05" placeholder="请输入读数" />
    </el-form-item>
    <el-form-item label="备注" prop="detail[1].rem1">
      <el-input v-model="modelData.detail[1].rem1" placeholder="请输入备注" />
    </el-form-item>
  </el-form>
</template>
<script setup lang="ts">
import { EquipHouseApi, EquipHouseListReqVO, EquipHouseVO } from '@/api/iotmanage/equiphouse'

const queryParams = reactive<EquipHouseListReqVO>({
  houseId: '',
  status1: undefined,
  vdef1: undefined
})

const props = defineProps({
  busScope: {
    type: String,
    required: true
  }
})
const formRef = ref()
const rules = reactive({
  'detail[1].equipId': [{ required: true, message: '设备不能为空', trigger: 'blur' }],
  'detail[1].effTime': [{ required: true, message: '生效时间不能为空', trigger: 'blur' }],
  'detail[1].bv01': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[1].bv02': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[1].bv03': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[1].bv04': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[1].bv05': [{ required: true, message: '读数不能为空', trigger: 'blur' }],
  'detail[1].houseId': [{ required: true, message: '房产id不能为空', trigger: 'blur' }],
  'detail[1].customerId': [{ required: true, message: '客户id不能为空', trigger: 'blur' }],
  billNo: [{ required: true, message: '单据号不能为空', trigger: 'blur' }]
})
// 创建本地数据副本
const modelData = defineModel<any>()

/** 表单校验 */
const validate = async () => {
  await formRef.value?.validate()
}
defineExpose({
  validate
})
const equipList = ref<EquipHouseVO[]>([])
const getList = async () => {
  equipList.value = await EquipHouseApi.listEquipHouse(queryParams)
  console.log(equipList.value)
}
onMounted(() => {
  queryParams.houseId = modelData.value.detail[1].houseId
  queryParams.status1 = 1
  queryParams.vdef1 = 2
  getList()
})
</script>
